const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");

module.exports = {
  mode: "production",
  entry: "./src/main.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "js/[name][hash:6].js",
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
      {
        test: /\.less$/,
        use: [
          {
            loader: "style-loader", // creates style nodes from JS strings
          },
          {
            loader: "css-loader", // translates CSS into CommonJS
          },
          {
            loader: "less-loader", // compiles Less to CSS
          },
        ],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.relative(__dirname, "./src/public/index.html"),
      filename: "./index.html",
      hash: true,
    }),
    new VueLoaderPlugin(),
  ],

  // 所有配置的内容都是写在最外层的
  devServer: {
    port: 8080,
    open: true,
    proxy: {
      "/api": {
        target: "https://i.maoyan.com",
        changeOrigin: true,
      },
    },
  },

  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      com: path.resolve(__dirname, "src/components"),
    },
    extensions: [".js", ".json", ".vue"],
  },
};
